package com.ygxsk.carhome.ui.adapter;

import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.flyco.roundview.RoundTextView;
import com.ygxsk.carhome.R;
import com.ygxsk.carhome.enumwrap.InfoMationAuditStatus;
import com.ygxsk.carhome.response.ArchivesManageFileMy;
import com.ygxsk.carhome.response.ArchivesManageImage;
import com.ygxsk.carhome.utils.CommUtils;

import java.util.ArrayList;
import java.util.List;

import cn.bingoogolapple.photopicker.widget.BGANinePhotoLayout;

/*
 * @Author:itchenqi175@163.com
 * @Time:2024/2/23  13:36
 * @Description:档案附件的详情的 动态分配的九宫格
 */
public class ArchiveDetailFootAdapter extends BaseQuickAdapter<ArchivesManageFileMy, BaseViewHolder> {


    //填充一个代理进去,因为涉及到权限申请 放在activity之中用；
    private BGANinePhotoLayout.Delegate bgaNinePhotoLayoutDelegate;

    private String auditStatus;

    public void setBgaNinePhotoLayoutDelegate(BGANinePhotoLayout.Delegate _bgaNinePhotoLayoutDelegate) {
        bgaNinePhotoLayoutDelegate = _bgaNinePhotoLayoutDelegate;
    }

    public ArchiveDetailFootAdapter(int layoutResId, @Nullable List<ArchivesManageFileMy> data, String _auditStatus) {
        super(layoutResId, data);

        auditStatus = _auditStatus;
        addChildClickViewIds(R.id.roundtextvieweditimagesitem);

    }

    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, ArchivesManageFileMy archivesManageFileMy) {

        if (archivesManageFileMy != null) {

            //附件九宫格的标题
            String fileTypeName = archivesManageFileMy.getFileTypeName();
            //九宫格内容
            ArrayList<ArchivesManageImage> archivesManageImage = archivesManageFileMy.getImages();

            //findviews
            //标题内容
            TextView textViewTitleCustomerItem = (TextView) baseViewHolder.getView(R.id.textviewtitlecustomeritem);
            RoundTextView roundTextViewEditImagesItem = (RoundTextView) baseViewHolder.getView(R.id.roundtextvieweditimagesitem);
            //九宫格填充
            BGANinePhotoLayout npl_item_moment_photos_file_detail = (BGANinePhotoLayout) baseViewHolder.getView(R.id.npl_item_moment_photos_file_detail_item);
            //底部分割线条
            TextView textViewTitleLineSplit = (TextView) baseViewHolder.getView(R.id.textviewtitlelinesplit);

            CommUtils.setText(textViewTitleCustomerItem, fileTypeName);

            //-------------------------------------------------------------------

            if (TextUtils.equals(auditStatus, String.valueOf(InfoMationAuditStatus.AUDITSTATUS_INPUTING.getIndex()))//
                    || TextUtils.equals(auditStatus, String.valueOf(InfoMationAuditStatus.AUDITSTATUS_TO_BE_VERIFY.getIndex()))//
                    || TextUtils.equals(auditStatus, String.valueOf(InfoMationAuditStatus.AUDITSTATUS_NOT_PASS.getIndex()))//
            ) {

                CommUtils.setViewVisible(roundTextViewEditImagesItem);

            } else if (TextUtils.equals(auditStatus, String.valueOf(InfoMationAuditStatus.AUDITSTATUS_HAS_PASS.getIndex()))) {
                CommUtils.setViewGone(roundTextViewEditImagesItem);
            }

            //-------------------------------------------------------------------
            //填充九宫格内容
            //九宫格图片的查看信息：
            ArrayList<String> imageUrlList = new ArrayList<>();

            if (archivesManageImage != null && !archivesManageImage.isEmpty()) {
                for (ArchivesManageImage archivesManageImageItem : archivesManageImage) {
                    String currtUrl = archivesManageImageItem.getFileName();
                    imageUrlList.add(currtUrl);
                }
            }

            npl_item_moment_photos_file_detail.setData(imageUrlList);

            //-------------------------------------------------------------------

            if (bgaNinePhotoLayoutDelegate != null) {
                npl_item_moment_photos_file_detail.setDelegate(bgaNinePhotoLayoutDelegate);
            }


            //如果是最后一条数据那么去掉分割
            int indexPosition = getItemPosition(archivesManageFileMy);

            if (indexPosition == getData().size() - 1) {
                textViewTitleLineSplit.setVisibility(View.INVISIBLE);
            } else {
                textViewTitleLineSplit.setVisibility(View.VISIBLE);
            }

        }

    }
}
